﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TPAMain数据维护工具V2
{
    public partial class frmSetConnectString : Form
    {
        public frmSetConnectString()
        {
            InitializeComponent();
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(GeneralTools.GetConnectionString(txtHost.Text, txtDBName.Text ));
            try
            {
                conn.Open();
                GeneralTools.ShowInfoMsg("连接成功！");
            }
            catch(Exception ex)
            {
                GeneralTools.ShowErrorMsg("连接失败！错误信息：" + ex.Message);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.Host = txtHost.Text.Trim();
            Properties.Settings.Default.DBName = txtDBName.Text.Trim();
            Properties.Settings.Default.Save();
            GeneralTools.ShowInfoMsg("设置已保存！重启软件后生效！");
            this.Close();
        }
    }
}
